<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>SPI master loopback usage example</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51 General Code Examples
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('group__spi__master__example.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#define-members">Defines</a> &#124;
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle">
<div class="title">SPI master loopback usage example</div>  </div>
<div class="ingroups"><a class="el" href="group__nrf__examples__nrf6310.html">nRF6310 example projects</a></div></div>
<div class="contents">

<p>SPI master example.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="define-members"></a>
Defines</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__spi__master__example.html#ga70fb43de88d474f4c6e87dff47edf851">DELAY_MS</a>&#160;&#160;&#160;100</td></tr>
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__spi__master__example.html#gad4d06277ef5012bb818ae4b32eb1b8d2">test_spi_tx_rx</a> (<a class="el" href="group__lib__driver__spi__master.html#gac859abd9dbf0e642ef29753f142f4475">SPIModuleNumber</a> mod_num, uint8_t lsb_first)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__spi__master__example.html#ga840291bc02cba5474a4cb46a9b9566fe">main</a> (void)</td></tr>
<tr><td colspan="2"><h2><a name="var-members"></a>
Variables</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static uint8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__spi__master__example.html#gab36e6efd0ec4bf8a1f51555850828b5a">tx_data</a> [TX_RX_MSG_LENGTH]</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static uint8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__spi__master__example.html#gae4cee0b144cc6cb01fc4c7b36e37a874">rx_data</a> [TX_RX_MSG_LENGTH]</td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<p>SPI master example. </p>
<p>This example needs that the slave is configured to transmit the received bytes. That is the slave behaves as a loopback device for the master. The loopback can also be achieved without using a slave device at all by wiring MOSI and MISO pins of the spi master together. TX_RX_MSG_LENGTH number of bytes are transmitted through the master and the received bytes are verified to be the same as transmitted. IF there is an error, gpio pin for relevant spi module is set high to show the error </p>
<dl class="see"><dt><b>See also:</b></dt><dd>ERROR_PIN_SPI0, </dd>
<dd>
ERROR_PIN_SPI1. If there is error from both modules that is if both pins are set high, then this application loops for ever </dd></dl>
<hr/><h2>Define Documentation</h2>
<a class="anchor" id="ga70fb43de88d474f4c6e87dff47edf851"></a><!-- doxytag: member="main.c::DELAY_MS" ref="ga70fb43de88d474f4c6e87dff47edf851" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define DELAY_MS&#160;&#160;&#160;100</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Timer Delay in milli-seconds </p>

<p>Definition at line <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html#l00037">37</a> of file <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="gad4d06277ef5012bb818ae4b32eb1b8d2"></a><!-- doxytag: member="main.c::test_spi_tx_rx" ref="gad4d06277ef5012bb818ae4b32eb1b8d2" args="(SPIModuleNumber mod_num, uint8_t lsb_first)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">static bool test_spi_tx_rx </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__lib__driver__spi__master.html#gac859abd9dbf0e642ef29753f142f4475">SPIModuleNumber</a>&#160;</td>
          <td class="paramname"><em>mod_num</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint8_t&#160;</td>
          <td class="paramname"><em>lsb_first</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Tests SPI master. </p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">lsb_first</td><td>If true, least significant bits are transferred first </td></tr>
    <tr><td class="paramname">mod_num</td><td>spi module to be used, either SPI0 or SPI1 from enumeration SPIModuleNumber </td></tr>
  </table>
  </dd>
</dl>
<dl><dt><b>Return values:</b></dt><dd>
  <table class="retval">
    <tr><td class="paramname">true</td><td></td></tr>
    <tr><td class="paramname">false</td><td>Error occurred </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html#l00045">45</a> of file <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="ga840291bc02cba5474a4cb46a9b9566fe"></a><!-- doxytag: member="main.c::main" ref="ga840291bc02cba5474a4cb46a9b9566fe" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int main </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p><a class="el" href="group__gpio__example.html#ga840291bc02cba5474a4cb46a9b9566fe">main()</a> function </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>0. int return type required by ANSI/ISO standard. </dd></dl>
<p>&lt; test with shift Lsb first mode 0</p>
<p>&lt; This delay is just fot the events ready signal to be visually clear if connted to LED if DEBUG flag is enabled in spi_master library</p>
<p>&lt; test with shift Lsb first mode 0</p>
<p>&lt; This delay is just fot the events ready signal to be visually clear if connted to LED if DEBUG flag is enabled in spi_master library </p>

<p>Definition at line <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html#l00077">77</a> of file <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<hr/><h2>Variable Documentation</h2>
<a class="anchor" id="gab36e6efd0ec4bf8a1f51555850828b5a"></a><!-- doxytag: member="main.c::tx_data" ref="gab36e6efd0ec4bf8a1f51555850828b5a" args="[TX_RX_MSG_LENGTH]" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint8_t <a class="el" href="group__spi__master__example.html#gab36e6efd0ec4bf8a1f51555850828b5a">tx_data</a>[TX_RX_MSG_LENGTH]<code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>SPI TX buffer </p>

<p>Definition at line <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html#l00034">34</a> of file <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
<a class="anchor" id="gae4cee0b144cc6cb01fc4c7b36e37a874"></a><!-- doxytag: member="main.c::rx_data" ref="gae4cee0b144cc6cb01fc4c7b36e37a874" args="[TX_RX_MSG_LENGTH]" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint8_t <a class="el" href="group__spi__master__example.html#gae4cee0b144cc6cb01fc4c7b36e37a874">rx_data</a>[TX_RX_MSG_LENGTH]<code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>SPI RX buffer </p>

<p>Definition at line <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html#l00035">35</a> of file <a class="el" href="nrf6310_2spi__master__example_2main_8c_source.html">main.c</a>.</p>

</div>
</div>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
